﻿using System; 
using System.Runtime.CompilerServices;
using AchSegítő.File;
using AchSegítő.Tests.attribute;
using ApprovalTests;
using Microsoft.VisualStudio.TestTools.UnitTesting; 

namespace AchSegítő.Tests
{
    /// <summary>
    /// Summary description for ACHFileWriterTests
    /// </summary> 
    [TestClass]
    public class AchFileWriterTests
    {
        // Test Cases:
        // File header
        // File control
        // Batch header
        // Batch control
        // Detail entry
        // Full file generation(s)
        // Ensure file is "blocked"
        
        [TestMethod,Unit] 
        [ApprovalTests.Reporters.UseReporter(typeof(ApprovalTests.Reporters.MsTestReporter))]
        [MethodImpl(MethodImplOptions.NoInlining)]
        public void GenerateFile()
        {
            var x = new ACH
            {
                Header = new FileHeader()
                {
                    ImmediateDestination = "051000033",
                    ImmediateOrigin = "059999997",
                    FileCreationDateTime = DateTime.Parse("10/6/2016"),
                    ImmediateDestinationName = "TCB Services",
                    ImmediateOriginName = "My TRUST"
                },
                Batches = new[]
                {
                    new Batch()
                    {
                        Header = new BatchHeader()
                        {
                            CompanyName = "Körülfon Inc.",
                            CompanyDiscreationaryData = "INCLUDES OVERTIME",
                            CompanyId = "141987123",
                            CompanyDescriptiveDate = DateTime.Parse("10/1/2015"),
                            EffectiveEntryDate = DateTime.Parse("10/7/2015"),
                            OriginatingDFIIdentification = "1099912",
                            BatchNumber = 3400001
                        },
                        Entries = new[]
                        {
                            new EntryDetail()
                            {
                                ReceivingDFIIdentification = "03100005",
                                CheckDigit = '3',
                                DFIAccountNumber = "1234567890",
                                Amount = 100.00m,
                                IndividualName = "Wagers, Matt",
                                TraceNumber = "0310000500001",
                                TransactionCode = TransactionCode.CheckingCredit
                            },
                            new EntryDetail()
                            {
                                ReceivingDFIIdentification = "03100005",
                                CheckDigit = '3',
                                DFIAccountNumber = "1234567891",
                                Amount = 150.00m,
                                IndividualName = "Bowling, Jason",
                                TraceNumber = "0310000500002",
                                TransactionCode = TransactionCode.SavingCredit
                            }
                        }
                    }
                }
            }.Generate();
            Assert.IsNotNull(x);
        }

        [TestMethod]
        [ApprovalTests.Reporters.UseReporter(typeof (ApprovalTests.Reporters.MsTestReporter))]
        [MethodImpl(MethodImplOptions.NoInlining)]
        public void GenerateHeader()
        { 
            var x = new FileHeader()
            {
                ImmediateDestination = "051000033",
                ImmediateOrigin = "059999997",
                FileCreationDateTime = DateTime.Parse("10/6/2016"),
                ImmediateDestinationName = "TCB Services",
                ImmediateOriginName = "My TRUST"
            }.ToString();
            
            Assert.IsNotNull(x); 
        }

        [TestMethod]
        [ApprovalTests.Reporters.UseReporter(typeof (ApprovalTests.Reporters.MsTestReporter))]
        [MethodImpl(MethodImplOptions.NoInlining)]
        public void GenerateFileControl()
        {
            var x = new ACH
            {
                Header = new FileHeader
                {
                    ImmediateDestination = "051000033",
                    ImmediateOrigin = "059999997",
                    FileCreationDateTime = DateTime.Parse("10/6/2016"),
                    ImmediateDestinationName = "TCB Services",
                    ImmediateOriginName = "My TRUST"
                },
                Batches = new[]
                {
                    new Batch
                    {
                        Header = new BatchHeader
                        {
                            CompanyName = "Körülfon Inc.",
                            CompanyDiscreationaryData = "INCLUDES OVERTIME",
                            CompanyId = "141987123",
                            CompanyDescriptiveDate = DateTime.Parse("10/1/2015"),
                            EffectiveEntryDate = DateTime.Parse("10/7/2015"),
                            OriginatingDFIIdentification = "1099912",
                            BatchNumber = 3400001
                        },
                        Entries = new[]
                        {
                            new EntryDetail
                            {
                                ReceivingDFIIdentification = "03100005",
                                CheckDigit = '3',
                                DFIAccountNumber = "1234567890",
                                Amount = 100.00m,
                                IndividualName = "Wagers, Matt",
                                TraceNumber = "0310000500001",
                                TransactionCode = TransactionCode.CheckingCredit
                            },
                            new EntryDetail
                            {
                                ReceivingDFIIdentification = "03100005",
                                CheckDigit = '3',
                                DFIAccountNumber = "1234567891",
                                Amount = 150.00m,
                                IndividualName = "Bowling, Jason",
                                TraceNumber = "0310000500002",
                                TransactionCode = TransactionCode.SavingCredit
                            }
                        }
                    }
                }
            }.Control.ToString();
            Assert.IsNotNull(x);
        }

        [TestMethod]
        [ApprovalTests.Reporters.UseReporter(typeof (ApprovalTests.Reporters.MsTestReporter))]
        [MethodImpl(MethodImplOptions.NoInlining)]
        public void GenerateBatchHeader()
        {
            var x = new BatchHeader
            {
                ServiceClass = ServiceClassCode.Debits_Only,
                CompanyName = "Körülfon Inc.",
                CompanyDiscreationaryData = "INCLUDES OVERTIME",
                CompanyId = "141987123",
                CompanyDescriptiveDate = DateTime.Parse("10/1/2015"),
                EffectiveEntryDate = DateTime.Parse("10/7/2015"),
                OriginatingDFIIdentification = "1099912",
                BatchNumber = 3400001
            }.ToString();
            Assert.IsNotNull(x);
        }

        [TestMethod]
        [ApprovalTests.Reporters.UseReporter(typeof (ApprovalTests.Reporters.MsTestReporter))]
        [MethodImpl(MethodImplOptions.NoInlining)]
        public void GenerateBatchControle()
        {
            var x = new Batch
            {
                Header = new BatchHeader
                {
                    CompanyName = "Körülfon Inc.",
                    CompanyDiscreationaryData = "INCLUDES OVERTIME",
                    CompanyId = "141987123",
                    CompanyDescriptiveDate = DateTime.Parse("10/1/2015"),
                    EffectiveEntryDate = DateTime.Parse("10/7/2015"),
                    OriginatingDFIIdentification = "1099912",
                    BatchNumber = 3400001
                },
                Entries = new[]
                {
                    new EntryDetail
                    {
                        ReceivingDFIIdentification = "03100005",
                        CheckDigit = '3',
                        DFIAccountNumber = "1234567890",
                        Amount = 100.00m,
                        IndividualName = "Wagers, Matt",
                        TraceNumber = "0310000500001",
                        TransactionCode = TransactionCode.CheckingCredit
                    },
                    new EntryDetail
                    {
                        ReceivingDFIIdentification = "03100005",
                        CheckDigit = '3',
                        DFIAccountNumber = "1234567891",
                        Amount = 150.00m,
                        IndividualName = "Bowling, Jason",
                        TraceNumber = "0310000500002",
                        TransactionCode = TransactionCode.SavingCredit
                    }
                }
            }.Control.ToString();
            Assert.IsNotNull(x);
        }

        [TestMethod]
        [ApprovalTests.Reporters.UseReporter(typeof (ApprovalTests.Reporters.MsTestReporter))]
        [MethodImpl(MethodImplOptions.NoInlining)]
        public void GenerateDetailEntry()
        {
            var x = new EntryDetail
            {
                ReceivingDFIIdentification = "03100005",
                CheckDigit = '3',
                DFIAccountNumber = "1234567890",
                Amount = 100.00m,
                IndividualName = "Wagers, Matt",
                TraceNumber = "0310000500001",
                TransactionCode = TransactionCode.CheckingCredit
            }.ToString();
            Assert.IsNotNull(x);
        }

    }
}
